package com.zzzs.lock;

import lombok.SneakyThrows;
import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @author zhu_shuai
 * @since 8/17
 */
public class UnsafeTest {
    @SneakyThrows
    public static void main(String[] args) throws NoSuchFieldException {
        Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
        theUnsafe.setAccessible(true);
        Unsafe unsafe = (Unsafe) theUnsafe.get(null);
        Object o = new Object();
        int x = 1;
        boolean b = unsafe.compareAndSwapInt(o, o.hashCode(), x, 1);
        System.out.println(b);
        System.out.println(x);
    }
}
